// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   UpgradeMsgDialog.java

package com.boci.common.ui.control;

import com.boci.clientapp.main.ClientAppLoader;
import com.boci.clientapp.main.TradingClientApp;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractDialog;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import javax.swing.*;

// Referenced classes of package com.boci.common.ui.control:
//            CMURLButton

public class UpgradeMsgDialog extends AbstractDialog
    implements ActionListener
{

    public UpgradeMsgDialog(TradingClientApp owner, boolean modal, Locale pLocale)
    {
        super(owner, modal, pLocale, false);
        lblSubText = new JLabel();
        taMessage = new JTextArea();
        btnOK = new JButton();
        btnLink = new CMURLButton();
        msgPanel = new JPanel();
        btnPanel = new JPanel();
        pUpgradeCode = 0;
        mainFrame = owner;
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI(pLocale);
    }

    private void setFont(Locale pLocale)
    {
        taMessage.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnLink.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        lblSubText.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnOK.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
    }

    public void setText(Locale pLocale)
    {
        currentLocale = pLocale;
        super.setText(pLocale);
        setFont(pLocale);
        btnOK.setText(msgConf.getUIMessages("UPGRADE.OK", pLocale));
        if(pLocale.equals(ClientAppConst.EN_US))
            taMessage.setWrapStyleWord(true);
        else
            taMessage.setWrapStyleWord(false);
        if(strUpgradeCode != null && strUpgradeCode.length() > 0)
            setMessage(strDownloadURL, strUpgradeCode);
    }

    public void setMessage(String pUrl, String pUpgradeCode)
    {
        strUpgradeCode = pUpgradeCode.trim();
        strDownloadURL = pUrl;
        try
        {
            this.pUpgradeCode = Integer.parseInt(pUpgradeCode);
        }
        catch(Exception err) { }
        setTitle(msgConf.getUIMessages((new StringBuilder()).append("UPGRADE.TITLE_").append(strUpgradeCode).toString(), currentLocale));
        taMessage.setText(msgConf.getUIMessages((new StringBuilder()).append("UPGRADE.MESSAGE_").append(strUpgradeCode).toString(), currentLocale));
        btnLink.setText(msgConf.getUIMessages((new StringBuilder()).append("UPGRADE.URL_TEXT_").append(strUpgradeCode).toString(), currentLocale));
        lblSubText.setText(msgConf.getUIMessages((new StringBuilder()).append("UPGRADE.SUB_TEXT_").append(strUpgradeCode).toString(), currentLocale));
    }

    private void initGUI(Locale pLocale)
    {
        getContentPane().setLayout(new BorderLayout());
        getContentPane().setBackground(Color.WHITE);
        msgPanel.setLayout(null);
        msgPanel.setOpaque(false);
        btnPanel.setLayout(new FlowLayout());
        btnPanel.setOpaque(false);
        getContentPane().add(msgPanel, "Center");
        getContentPane().add(btnPanel, "South");
        setSize(400, 142);
        taMessage.setEditable(false);
        taMessage.setWrapStyleWord(true);
        taMessage.setLineWrap(true);
        taMessage.setBounds(5, 5, 380, 40);
        msgPanel.add(taMessage);
        taMessage.setOpaque(false);
        btnLink.setBounds(5, 40, 380, 20);
        btnLink.addActionListener(this);
        msgPanel.add(btnLink);
        btnLink.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        lblSubText.setBounds(5, 55, 380, 20);
        msgPanel.add(lblSubText);
        lblSubText.setHorizontalAlignment(0);
        btnPanel.add(btnOK);
        btnOK.addActionListener(this);
        setText(pLocale);
        setFont(pLocale);
    }

    public void showDialog(boolean pVisible)
    {
        if(pVisible)
        {
            setLocationRelativeTo(mainFrame);
            setVisible(pVisible);
        } else
        {
            super.showDialog(pVisible);
        }
    }

    public void refresh(ResponseVO responsevo)
    {
    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource().equals(btnLink))
        {
            if(ClientAppLoader.isStandalone())
                try
                {
                    Runtime.getRuntime().exec((new StringBuilder()).append("rundll32 url.dll,FileProtocolHandler ").append(strDownloadURL).toString());
                }
                catch(Exception ex) { }
        } else
        if(pUpgradeCode == 1)
            try
            {
                Runtime.getRuntime().exec((new StringBuilder()).append("rundll32 url.dll,FileProtocolHandler ").append(strDownloadURL).toString());
                System.exit(0);
            }
            catch(IOException e1) { }
        else
            super.showDialog(false);
    }

    public HashMap getInputValue(String pActionType)
    {
        return null;
    }

    public void setDefFocus()
    {
        btnOK.requestFocus();
    }

    JLabel lblSubText;
    JTextArea taMessage;
    JButton btnOK;
    CMURLButton btnLink;
    TradingClientApp mainFrame;
    JPanel msgPanel;
    JPanel btnPanel;
    String strDownloadURL;
    String strUpgradeCode;
    Locale currentLocale;
    MessagesConfigurator msgConf;
    int pUpgradeCode;
}
